<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Random Numbers</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
<link rel="start" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
<link rel="prev" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions">
<link rel="next" href="glib-Hook-Functions.html" title="Hook Functions">
<meta name="generator" content="GTK-Doc V1.9 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="glib.html" title="GLib Overview">
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
<link rel="chapter" href="tools.html" title="GLib Tools">
<link rel="index" href="ix01.html" title="Index">
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
<link rel="index" href="ix09.html" title="Index of new symbols in 2.14">
<link rel="index" href="ix10.html" title="Index of new symbols in 2.16">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Date-and-Time-Functions.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GLib Reference Manual</th>
<td><a accesskey="n" href="glib-Hook-Functions.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3107346" class="shortcut">Top</a>
                  &#160;|&#160;
                  <a href="#id3107807" class="shortcut">Description</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="glib-Random-Numbers"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id3107346"></a><span class="refentrytitle">Random Numbers</span>
</h2>
<p>Random Numbers &#8212; pseudo-random number generator</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">

#include &lt;glib.h&gt;


                    <a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>;
<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              <a class="link" href="glib-Random-Numbers.html#g-rand-new-with-seed">g_rand_new_with_seed</a>                (<a class="link" href="glib-Basic-Types.html#guint32">guint32</a> seed);
<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              <a class="link" href="glib-Random-Numbers.html#g-rand-new-with-seed-array">g_rand_new_with_seed_array</a>          (const <a class="link" href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                                         <a class="link" href="glib-Basic-Types.html#guint">guint</a> seed_length);
<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              <a class="link" href="glib-Random-Numbers.html#g-rand-new">g_rand_new</a>                          (void);
<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              <a class="link" href="glib-Random-Numbers.html#g-rand-copy">g_rand_copy</a>                         (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
void                <a class="link" href="glib-Random-Numbers.html#g-rand-free">g_rand_free</a>                         (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
void                <a class="link" href="glib-Random-Numbers.html#g-rand-set-seed">g_rand_set_seed</a>                     (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         <a class="link" href="glib-Basic-Types.html#guint32">guint32</a> seed);
void                <a class="link" href="glib-Random-Numbers.html#g-rand-set-seed-array">g_rand_set_seed_array</a>               (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         const <a class="link" href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                                         <a class="link" href="glib-Basic-Types.html#guint">guint</a> seed_length);
#define             <a class="link" href="glib-Random-Numbers.html#g-rand-boolean">g_rand_boolean</a>                      (rand_)
<a class="link" href="glib-Basic-Types.html#guint32">guint32</a>             <a class="link" href="glib-Random-Numbers.html#g-rand-int">g_rand_int</a>                          (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
<a class="link" href="glib-Basic-Types.html#gint32">gint32</a>              <a class="link" href="glib-Random-Numbers.html#g-rand-int-range">g_rand_int_range</a>                    (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         <a class="link" href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gint32">gint32</a> end);
<a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             <a class="link" href="glib-Random-Numbers.html#g-rand-double">g_rand_double</a>                       (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);
<a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             <a class="link" href="glib-Random-Numbers.html#g-rand-double-range">g_rand_double_range</a>                 (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         <a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> end);
void                <a class="link" href="glib-Random-Numbers.html#g-random-set-seed">g_random_set_seed</a>                   (<a class="link" href="glib-Basic-Types.html#guint32">guint32</a> seed);
#define             <a class="link" href="glib-Random-Numbers.html#g-random-boolean">g_random_boolean</a>                    ()
<a class="link" href="glib-Basic-Types.html#guint32">guint32</a>             <a class="link" href="glib-Random-Numbers.html#g-random-int">g_random_int</a>                        (void);
<a class="link" href="glib-Basic-Types.html#gint32">gint32</a>              <a class="link" href="glib-Random-Numbers.html#g-random-int-range">g_random_int_range</a>                  (<a class="link" href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gint32">gint32</a> end);
<a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             <a class="link" href="glib-Random-Numbers.html#g-random-double">g_random_double</a>                     (void);
<a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             <a class="link" href="glib-Random-Numbers.html#g-random-double-range">g_random_double_range</a>               (<a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> end);
</pre>
</div>
<div class="refsect1" lang="en">
<a name="id3107807"></a><h2>Description</h2>
<p>
The following functions allow you to use a portable, fast and good
pseudo-random number generator (PRNG). It uses the Mersenne Twister
PRNG, which was originally developed by Makoto Matsumoto and Takuji
Nishimura. Further information can be found at <a class="ulink" href="http://www.math.keio.ac.jp/~matumoto/emt.html" target="_top">www.math.keio.ac.jp/~matumoto/emt.html</a>.
</p>
<p>
If you just need a random number, you simply call the 
<code class="function">g_random_*</code> functions, which will create a globally 
used <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> and use the according <code class="function">g_rand_*</code> functions 
internally. Whenever you need a stream of reproducible random numbers, you 
better create a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> yourself and use the <code class="function">g_rand_*</code> 
functions directly, which will also be slightly faster. Initializing a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> 
with a certain seed will produce exactly the same series of random numbers 
on all platforms. This can thus be used as a seed for e.g. games.
</p>
<p>
The <code class="function">g_rand*_range</code> functions will return high quality
equally distributed random numbers, whereas for example the
<code class="literal">(<a class="link" href="glib-Random-Numbers.html#g-random-int"><code class="function">g_random_int()</code></a>%max)</code> approach often doesn't
yield equally distributed numbers.
</p>
<p>
GLib changed the seeding algorithm for the pseudo-random number
generator Mersenne Twister, as used by <span class="structname">GRand</span>
and <span class="structname">GRandom</span>. This was necessary, because some
seeds would yield very bad pseudo-random streams.  Also the
pseudo-random integers generated by
<code class="function">g_rand*<code class="function">_int_range()</code></code> will have a
slightly better equal distribution with the new version of GLib.
</p>
<p>
The original seeding and generation algorithms, as found in GLib 2.0.x,
can be used instead of the new ones by setting the environment variable
<code class="envar">G_RANDOM_VERSION</code> to the value of '2.0'. Use the
GLib-2.0 algorithms only if you have sequences of numbers generated
with Glib-2.0 that you need to reproduce exactly.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id3107957"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id3107968"></a><h3>
<a name="GRand"></a>GRand</h3>
<a class="indexterm" name="id3107980"></a><pre class="programlisting">typedef struct _GRand GRand;</pre>
<p>
The <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> struct is an opaque data structure. It should only be
accessed through the <code class="function">g_rand_*</code> functions.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108011"></a><h3>
<a name="g-rand-new-with-seed"></a>g_rand_new_with_seed ()</h3>
<a class="indexterm" name="id3108024"></a><pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              g_rand_new_with_seed                (<a class="link" href="glib-Basic-Types.html#guint32">guint32</a> seed);</pre>
<p>
Creates a new random number generator initialized with <em class="parameter"><code>seed</code></em>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>seed</code></em>&#160;:</span></p></td>
<td> a value to initialize the random number generator.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> the new <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108098"></a><h3>
<a name="g-rand-new-with-seed-array"></a>g_rand_new_with_seed_array ()</h3>
<a class="indexterm" name="id3108113"></a><pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              g_rand_new_with_seed_array          (const <a class="link" href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                                         <a class="link" href="glib-Basic-Types.html#guint">guint</a> seed_length);</pre>
<p>
Creates a new random number generator initialized with <em class="parameter"><code>seed</code></em>.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>seed</code></em>&#160;:</span></p></td>
<td> an array of seeds to initialize the random number generator.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>seed_length</code></em>&#160;:</span></p></td>
<td> an array of seeds to initialize the random number generator.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> the new <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.

</td>
</tr>
</tbody>
</table></div>
<p class="since">Since  2.4
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108218"></a><h3>
<a name="g-rand-new"></a>g_rand_new ()</h3>
<a class="indexterm" name="id3108230"></a><pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              g_rand_new                          (void);</pre>
<p>
Creates a new random number generator initialized with a seed taken
either from <code class="filename">/dev/urandom</code> (if existing) or from 
the current time (as a fallback).</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> the new <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108283"></a><h3>
<a name="g-rand-copy"></a>g_rand_copy ()</h3>
<a class="indexterm" name="id3108297"></a><pre class="programlisting"><a class="link" href="glib-Random-Numbers.html#GRand">GRand</a>*              g_rand_copy                         (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre>
<p>
Copies a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> into a new one with the same exact state as before.
This way you can take a snapshot of the random number generator for
replaying later.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> the new <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.

</td>
</tr>
</tbody>
</table></div>
<p class="since">Since  2.4
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108390"></a><h3>
<a name="g-rand-free"></a>g_rand_free ()</h3>
<a class="indexterm" name="id3108402"></a><pre class="programlisting">void                g_rand_free                         (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre>
<p>
Frees the memory allocated for the <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108465"></a><h3>
<a name="g-rand-set-seed"></a>g_rand_set_seed ()</h3>
<a class="indexterm" name="id3108478"></a><pre class="programlisting">void                g_rand_set_seed                     (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         <a class="link" href="glib-Basic-Types.html#guint32">guint32</a> seed);</pre>
<p>
Sets the seed for the random number generator <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a> to <em class="parameter"><code>seed</code></em>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>seed</code></em>&#160;:</span></p></td>
<td> a value to reinitialize the random number generator.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108570"></a><h3>
<a name="g-rand-set-seed-array"></a>g_rand_set_seed_array ()</h3>
<a class="indexterm" name="id3108585"></a><pre class="programlisting">void                g_rand_set_seed_array               (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         const <a class="link" href="glib-Basic-Types.html#guint32">guint32</a> *seed,
                                                         <a class="link" href="glib-Basic-Types.html#guint">guint</a> seed_length);</pre>
<p>
Initializes the random number generator by an array of
longs.  Array can be of arbitrary size, though only the
first 624 values are taken.  This function is useful
if you have many low entropy seeds, or if you require more then
32bits of actual entropy for your application.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>seed</code></em>&#160;:</span></p></td>
<td> array to initialize with
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>seed_length</code></em>&#160;:</span></p></td>
<td> length of array
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since  2.4
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108697"></a><h3>
<a name="g-rand-boolean"></a>g_rand_boolean()</h3>
<a class="indexterm" name="id3108710"></a><pre class="programlisting">#define             g_rand_boolean(rand_)</pre>
<p>
Returns a random <a class="link" href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> from <em class="parameter"><code>rand_</code></em>. This corresponds to a unbiased
coin toss.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td>a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>a random <a class="link" href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108784"></a><h3>
<a name="g-rand-int"></a>g_rand_int ()</h3>
<a class="indexterm" name="id3108797"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint32">guint32</a>             g_rand_int                          (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre>
<p>
Returns the next random <a class="link" href="glib-Basic-Types.html#guint32"><span class="type">guint32</span></a> from <em class="parameter"><code>rand_</code></em> equally distributed over
the range [0..2^32-1].</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3108877"></a><h3>
<a name="g-rand-int-range"></a>g_rand_int_range ()</h3>
<a class="indexterm" name="id3108890"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint32">gint32</a>              g_rand_int_range                    (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         <a class="link" href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gint32">gint32</a> end);</pre>
<p>
Returns the next random <a class="link" href="glib-Basic-Types.html#gint32"><span class="type">gint32</span></a> from <em class="parameter"><code>rand_</code></em> equally distributed over
the range [<em class="parameter"><code>begin</code></em>..<em class="parameter"><code>end</code></em>-1].</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>begin</code></em>&#160;:</span></p></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>end</code></em>&#160;:</span></p></td>
<td> upper open bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109026"></a><h3>
<a name="g-rand-double"></a>g_rand_double ()</h3>
<a class="indexterm" name="id3109038"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             g_rand_double                       (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_);</pre>
<p>
Returns the next random <a class="link" href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> from <em class="parameter"><code>rand_</code></em> equally distributed over
the range [0..1).</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109118"></a><h3>
<a name="g-rand-double-range"></a>g_rand_double_range ()</h3>
<a class="indexterm" name="id3109132"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             g_rand_double_range                 (<a class="link" href="glib-Random-Numbers.html#GRand">GRand</a> *rand_,
                                                         <a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> end);</pre>
<p>
Returns the next random <a class="link" href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> from <em class="parameter"><code>rand_</code></em> equally distributed over
the range [<em class="parameter"><code>begin</code></em>..<em class="parameter"><code>end</code></em>).</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>rand_</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="glib-Random-Numbers.html#GRand"><span class="type">GRand</span></a>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>begin</code></em>&#160;:</span></p></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>end</code></em>&#160;:</span></p></td>
<td> upper open bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109267"></a><h3>
<a name="g-random-set-seed"></a>g_random_set_seed ()</h3>
<a class="indexterm" name="id3109280"></a><pre class="programlisting">void                g_random_set_seed                   (<a class="link" href="glib-Basic-Types.html#guint32">guint32</a> seed);</pre>
<p>
Sets the seed for the global random number generator, which is used
by the <code class="function">g_random_*</code> functions, to <em class="parameter"><code>seed</code></em>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>seed</code></em>&#160;:</span></p></td>
<td> a value to reinitialize the global random number generator.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109341"></a><h3>
<a name="g-random-boolean"></a>g_random_boolean()</h3>
<a class="indexterm" name="id3109354"></a><pre class="programlisting">#define             g_random_boolean()</pre>
<p>
Returns a random <a class="link" href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a>. This corresponds to a unbiased coin toss.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>a random <a class="link" href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a>.


</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109401"></a><h3>
<a name="g-random-int"></a>g_random_int ()</h3>
<a class="indexterm" name="id3109413"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint32">guint32</a>             g_random_int                        (void);</pre>
<p>
Return a random <a class="link" href="glib-Basic-Types.html#guint32"><span class="type">guint32</span></a> equally distributed over the range
[0..2^32-1].</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109460"></a><h3>
<a name="g-random-int-range"></a>g_random_int_range ()</h3>
<a class="indexterm" name="id3109473"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint32">gint32</a>              g_random_int_range                  (<a class="link" href="glib-Basic-Types.html#gint32">gint32</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gint32">gint32</a> end);</pre>
<p>
Returns a random <a class="link" href="glib-Basic-Types.html#gint32"><span class="type">gint32</span></a> equally distributed over the range
[<em class="parameter"><code>begin</code></em>..<em class="parameter"><code>end</code></em>-1].</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>begin</code></em>&#160;:</span></p></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>end</code></em>&#160;:</span></p></td>
<td> upper open bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109573"></a><h3>
<a name="g-random-double"></a>g_random_double ()</h3>
<a class="indexterm" name="id3109586"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             g_random_double                     (void);</pre>
<p>
Returns a random <a class="link" href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> equally distributed over the range [0..1).</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3109632"></a><h3>
<a name="g-random-double-range"></a>g_random_double_range ()</h3>
<a class="indexterm" name="id3109645"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a>             g_random_double_range               (<a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> begin,
                                                         <a class="link" href="glib-Basic-Types.html#gdouble">gdouble</a> end);</pre>
<p>
Returns a random <a class="link" href="glib-Basic-Types.html#gdouble"><span class="type">gdouble</span></a> equally distributed over the range [<em class="parameter"><code>begin</code></em>..<em class="parameter"><code>end</code></em>).</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>begin</code></em>&#160;:</span></p></td>
<td> lower closed bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>end</code></em>&#160;:</span></p></td>
<td> upper open bound of the interval.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A random number.
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="refsect1" lang="en">
<a name="id3109747"></a><div class="refsect2" lang="en"><a name="id3109748"></a></div>
<hr>
<div class="refsect2" lang="en"><a name="id3109749"></a></div>
</div>
</div>
</body>
</html>
